#coding=utf8
from . import user
import json
from flask import render_template, request, url_for, jsonify, Response

@user.route('/hello')
def hello():
	return 'hello'

@user.route('/carousel')
def carousel():
	data = {
		'rm': 'success',
		'rc': '200',
		'data': {
			'title': '',
			'duedate': '',
			'imgUrl': '',
			'heat': 100
		}
	}
	return json.dumps(data)

@user.route('/details')
def details():
	article_id = request.values.get('id')
	print article_id
	return render_template('js_article2.html')

@user.route('/contents')
def contents():
	return render_template('js_content.html')

@user.route("/img/<imageid>")
def index(imageid):
	filepath = "./app/static/uploads/{}.jpg".format(imageid)
	image = file(filepath)
	resp = Response(image, mimetype="image/jpeg")
	return resp

@user.route('/home', methods=['GET', 'POST'])
def home():
	chid = request.values.get('chid')
	page = request.values.get('page')
	print 'chid', chid
	print 'page', page

	newsList = [
		{
            "id": '10',
            "title": '第九届校园十佳歌手比赛',
            "image": 'http://39.107.109.49:3389/user/img/201803231946349c1542a502704538819608f2bed0174a',
            "deadLine": '截止日期：2018-1-23',
            "group": '软微研究生会',
            "date": '2017-12-1',
            "hotNum": '300'
        }
	]
	newsList = newsList * 12

	newsBanner = [
		{
            "id": '3',
            "title": '第九届校园十佳歌手比赛',
            "image": 'http://39.107.109.49:3389/user/img/201803231947237768a236be25415092ec5741e2f7a517',
            "deadLine": '截止日期：2018-1-23',
            "hotNum": '300'
        }
	]
	newsBanner = newsBanner * 4

	data = {
		"code": 0,
		"newsList": newsList,
		"newsBanner": newsBanner
	}

	print data

	return jsonify(data)
